﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Threading;

namespace Tools.Debugging {
    public class Logger {
        private Logger ( ) { }

        static Logger ( ) {
            Debug( typeof( Logger ), " --- logging started" );
        }
        private static bool doprint ( ) {

            return true;//Thread.CurrentThread.ManagedThreadId == 11;
        }
        private static bool doprint ( Object o ) {

            return
                true
                //||
                //Thread.CurrentThread.ManagedThreadId == 12
                //||
                //Thread.CurrentThread.ManagedThreadId == 15
                ;
        }

        public static void Debug ( object o, String format, params object[] objs ) {
            String message = String.Format( format, objs );
            Debug( o, message );
        }

        public static void Debug ( object o, String message ) {
            if ( doprint( o ) ) {
                Thread thread = Thread.CurrentThread;
                String threadName = thread.Name + " I" + thread.ManagedThreadId;
                Console.WriteLine( "{0}, {1}[{5}] ({3}:{4}) :: {2}", DateTime.Now.ToString( "mm:ss.fff" ), o.GetType( ).Name, message, thread.Name, thread.ManagedThreadId, o.GetHashCode( ) );
            }
        }

        public static void Debug ( Type type, String format, params object[] objs ) {
            Debug( type, String.Format( format, objs ) );
        }

        public static void Debug ( Type type, String message ) {
            if ( doprint( ) ) {
                Thread thread = Thread.CurrentThread;
                String threadName = thread.Name + " I" + thread.ManagedThreadId;

                Console.WriteLine( "{0}, {1}[static] ({3}:{4}) :: {2}", DateTime.Now.ToString( "mm:ss.fff" ), type.Name, message, thread.Name, thread.ManagedThreadId );
            }
        }


        public static void Created ( object o ) {
            Debug( o, "created" );
        }



        public static void Exception ( object o, string message, Exception e ) {
            Thread thread = Thread.CurrentThread;
            String threadName = thread.Name + " I" + thread.ManagedThreadId;
            Console.WriteLine( "{0}, {1}[{5}] ({3}:{4}) :: {2}\nmethod:{6}\ntrace\n{7}", DateTime.Now.ToString( "mm:ss.fff" ), o.GetType( ).Name, message, thread.Name, thread.ManagedThreadId, o.GetHashCode( ), e.TargetSite.ToString( ), e.StackTrace );

        }
    }
}
